<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="favicon.ico"> <link href="./src/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="./src/css/font-awesome.css?v=4.4.0" rel="stylesheet">
        <link href="./src/css/plugins/iCheck/custom.css" rel="stylesheet">
        <link href="./src/css/animate.css" rel="stylesheet">
        <link href="./src/css/style.css?v=4.1.0" rel="stylesheet">
        <link href="./src/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    </head>
    <body>
        <div class="ibox-content">
            <form class="form-horizontal">
                <input type="hidden" name="m" value="index">
                <input type="hidden" name="a" value="costinformation">
                <div class="form-group">
                    <label class="col-sm-2 control-label" style="width: 100px;">费用编号：</label>

                    <div class="col-sm-2">
                        <input  class="form-control m-b" name="number" style="padding-top:2px;" value="<?php echo $this->number ?>">
                    </div>
                    <label class="col-sm-2 control-label" style="width: 100px;">费用名称：</label>

                    <div class="col-sm-2">
                        <input  class="form-control m-b" name="name" style="padding-top:2px;" value="<?php echo $this->name ?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" style="width: 100px;">费用类型：</label>

                    <div class="col-sm-2">
                        <select class="form-control m-b" name="type" style="padding-top:2px;">
                            <option value='0' >请选择</option>
                            <option value='1' <?php echo ($this->type == 1) ? 'selected' : '' ?> >应收</option>
                            <option value='2' <?php echo ($this->type == 2) ? 'selected' : '' ?> >应付</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label" style="width: 100px;">当前状态：</label>

                    <div class="col-sm-2">
                        <select class="form-control m-b" name="status" style="padding-top:2px;">
                            <option value='0'>全部</option>
                            <option value='1' <?php echo ($this->status == 1) ? 'selected' : '' ?> >激活</option>
                            <option value='2' <?php echo ($this->status == 2) ? 'selected' : '' ?> >休眠</option>
                        </select>
                    </div>
                    <div class="col-sm-1">
                        <button class="btn btn-sm btn-info" type="submit">搜索</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="row">
            <div class="ibox float-e-margins" style="width:98%;margin-left:1%;">
                <div class="ibox-title">
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#myModal5"><span class="bold">新增</span></button>
                    <div style="display: none;"><button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#myModal6" id="update"><span class="bold">修改</span></button></div>   
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" id="toupdate"><span class="bold">修改</span></button> 
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" id="delete"><span class="bold">删除</span></button>    
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" id="dormancy"><span class="bold">休眠</span></button>    
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" id="activation"><span class="bold">激活</span></button>    
                </div>
                <div class="ibox-content">

                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>排序</th>
                                <th>费用名称</th>
                                <th>费用编号</th>
                                <th>默认金额</th>
                                <th>是否自动</th>
                                <th>是否交税</th>
                                <th>是否参与利润计算</th>
                                <th>排列顺序</th>
                                <th>费用类型</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($this->data as $k => $v) { ?>
                                <tr>
                            <input type="hidden" value="<?php echo $v['id'] ?>">
                               <td><?php echo $v['id'] ?></td>
                            <td><?php echo $v['name'] ?></td>
                            <td><?php echo $v['number'] ?></td>
                            <td><?php echo $v['defaultcost'] ?></td>
                            <td><?php echo ($v['is_automaticint'] == 1) ? '是' : '否' ?></td>
                            <td><?php echo ($v['is_paytaxes'] == 1 ) ? '是' : '否' ?></td>
                            <td><?php echo ($v['is_profit'] == 1) ? '是' : '否' ?></td>
                            <td>1</td>
                            <td><?php echo ($v['type'] == 1) ? '应收' : '应付' ?></td>
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>

                </div>
            </div>
        </div>
        <div class="admin-table-page" style="margin-left:20px;">
            <div id="page" class="page">
                <?php echo $this->paging; ?>
            </div>
        </div>
        <div class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">费用信息新增</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal">
                            <div class="form-group">

                                <label class="col-sm-2 control-label">费用名称：</label>
                                <div class="col-sm-3">
                                    <input class="form-control m-b" id="name" name="account">
                                </div>
                                <label class="col-sm-2 control-label">费用编号：</label>
                                <div class="col-sm-3">
                                    <input class="form-control m-b" id="number" name="account">
                                </div>

                            </div>
                            <div class="form-group">

                                <label class="col-sm-2 control-label">默认金额：</label>
                                <div class="col-sm-3">
                                    <input class="form-control m-b" id="defaultcost" name="account">
                                </div>
                                <label class="col-sm-2 control-label">是否自动：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="is_automaticint" style="padding-top:2px;">
                                        <option value='1' class="is_automaticint_1" >是</option>
                                        <option value='0' class="is_automaticint_0" >否</option>
                                    </select>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否交税：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="is_paytaxes" style="padding-top:2px;">
                                        <option value='1' class="is_paytaxes_1" >是</option>
                                        <option value='0' class="is_paytaxes_0" >否</option>
                                    </select>
                                </div>
                                <label class="col-sm-2 control-label">参与利润计算：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="is_profit" style="padding-top:2px;">
                                        <option value='1' class="is_profit_1" >是</option>
                                        <option value='0' class="is_profit_0" >否</option>
                                    </select>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">费用类型：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="type" style="padding-top:2px;">
                                        <option value='1' class="type_1" >应收</option>
                                        <option value='0' class="type_0" >应付</option>
                                    </select>
                                </div>

                            </div>
                        </form>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" id="gb" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="baocun">保存</button>
                    </div>
                </div>
            </div>
        </div>


        <div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">费用信息新增</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal">
                            <div class="form-group">

                                <label class="col-sm-2 control-label">费用名称：</label>
                                <div class="col-sm-3">
                                    <input class="form-control m-b" id="uname" name="account">
                                </div>
                                <label class="col-sm-2 control-label">费用编号：</label>
                                <div class="col-sm-3">
                                    <input class="form-control m-b" id="unumber" name="account">
                                </div>

                            </div>
                            <div class="form-group">

                                <label class="col-sm-2 control-label">默认金额：</label>
                                <div class="col-sm-3">
                                    <input class="form-control m-b" id="udefaultcost" name="account">
                                </div>
                                <label class="col-sm-2 control-label">是否自动：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="uis_automaticint" style="padding-top:2px;">
                                        <option value='1' class="is_automaticint_1" >是</option>
                                        <option value='0' class="is_automaticint_0" >否</option>
                                    </select>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">是否交税：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="uis_paytaxes" style="padding-top:2px;">
                                        <option value='1' class="is_paytaxes_1" >是</option>
                                        <option value='0' class="is_paytaxes_0" >否</option>
                                    </select>
                                </div>
                                <label class="col-sm-2 control-label">参与利润计算：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="uis_profit" style="padding-top:2px;">
                                        <option value='1' class="is_profit_1" >是</option>
                                        <option value='0' class="is_profit_0" >否</option>
                                    </select>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">费用类型：</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" id="utype" style="padding-top:2px;">
                                        <option value='1' class="type_1" >应收</option>
                                        <option value='0' class="type_0" >应付</option>
                                    </select>
                                </div>

                            </div>
                        </form>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" id="gb" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="ubaocun">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <script src="./src/js/jquery.min.js?v=2.1.4"></script>
        <script src="./src/js/bootstrap.min.js?v=3.3.6"></script>



        <!-- 自定义js -->
        <script src="./src/js/content.js?v=1.0.0"></script>
        <script src="./src/js/plugins/sweetalert/sweetalert.min.js"></script>
        <script>
            $(function() {


                $("tr:gt(0)").click(function() {
                    ID = $(this).find("input").val();
                    $("tr").removeClass("bkcl");
                    $(this).addClass("bkcl");
                });
                //        $("#baocun").click(function(){
                //        });
                $('#baocun').click(function() {
                    var name = $("#name").val();
                    var number = $("#number").val();
                    var defaultcost = $("#defaultcost").val();
                    var is_automaticint = $("#is_automaticint").val();
                    var is_paytaxes = $("#is_paytaxes").val();
                    var is_profit = $("#is_profit").val();
                    var type = $("#type").val();
                    $.post("./?m=index&a=docost", {name: name, number: number, defaultcost: defaultcost, is_automaticint: is_automaticint, is_paytaxes: is_paytaxes, is_profit: is_profit, type: type}, function(result) {
                        if (result > 0) {
                            swal({
                                title: "提交数据成功",
                                text: "Submit data successfully"
                            }, function() {
                                location.href = "./?m=index&a=costinformation";
                            })
                        } else {
                            swal({
                                title: "提交数据失败",
                                text: "Failed to submit data"
                            });
                        }
                        ;
                    });

                });

                $("#toupdate").click(function() {
                    if (ID) {
                        $.get("./?m=index&a=costjson&id=" + ID, function(data) {
                            data = eval("(" + data + ")");
                            theid = data['id'];
                            $("#uname").val(data['name']);
                            $("#unumber").val(data['number']);
                            $("#udefaultcost").val(data['defaultcost']);
                            $(".is_automaticint_" + data['is_automaticint']).prop("selected", true);
                            $(".is_paytaxes_" + data['is_paytaxes']).prop("selected", true);
                            $(".is_profit_" + data['is_profit']).prop("selected", true);
                            $(".type_" + data['type']).prop("selected", true);
                        });
                        // return false;
                        $("#update").click();
                    }
                });

                $('#ubaocun').click(function() {
                    var name = $("#uname").val();
                    var number = $("#unumber").val();
                    var defaultcost = $("#udefaultcost").val();
                    var is_automaticint = $("#uis_automaticint").val();
                    var is_paytaxes = $("#uis_paytaxes").val();
                    var is_profit = $("#uis_profit").val();
                    var type = $("#utype").val();
                    $.post("./?m=index&a=costupdate", {id: theid, name: name, number: number, defaultcost: defaultcost, is_automaticint: is_automaticint, is_paytaxes: is_paytaxes, is_profit: is_profit, type: type}, function(result) {
                        if (result > 0) {
                            swal({
                                title: "数据修改成功",
                                text: "Data modification success"
                            }, function() {
                                location.href = "./?m=index&a=costinformation";
                            })
                        } else {
                            swal({
                                title: "数据修改失败",
                                text: "Data modification failed"
                            });
                        }
                    });

                });
                
               $("#dormancy").click(function(){
                           $.get("./?m=index&a=costdormancy&id="+ID,function(result){
                        if(result > 0){
                             swal({
                                title: "休眠成功",
                                text: "Data modification success"
                            }, function() {
                                location.href = "./?m=index&a=costinformation";
                            })
                        }
                    });
               });
               $("#activation").click(function(){
                           $.get("./?m=index&a=costactivation&id="+ID,function(result){
                        if(result > 0){
                             swal({
                                title: "激活成功",
                                text: "Data modification success"
                            }, function() {
                                location.href = "./?m=index&a=costinformation";
                            })
                        }
                    });
               });

                $('#delete').click(function() {
                    if (ID) {

                    } else {
                        return false;
                    }
                    swal({
                        title: "您确定要删除这条信息吗",
                        text: "请谨慎操作！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "删除",
                        cancelButtonText: "取消",
                        closeOnConfirm: false
                    }, function() {
                        $.get("./?m=index&a=costdelete&id=" + ID, function(result) {
                            if (result) {
                                swal({
                                    title: "成功删除",
                                    text: "这条数据将不会出在页面中显示",
                                    type: "success",
                                }, function() {
                                    location.href = "./?m=index&a=costinformation";
                                });
                            } else {
                                swal({
                                    title: "删除失败",
                                    type: "error",
                                });
                            }
                        });

                    });
                });
            });
        </script>
    </body>
</html>
